package com.hxrfid.web.controller.project;

import com.hxrfid.common.annotation.Log;
import com.hxrfid.common.annotation.RepeatSubmit;
import com.hxrfid.common.core.controller.BaseController;
import com.hxrfid.common.core.domain.PageQuery;
import com.hxrfid.common.core.domain.R;
import com.hxrfid.common.core.page.TableDataInfo;
import com.hxrfid.common.core.validate.AddGroup;
import com.hxrfid.common.core.validate.EditGroup;
import com.hxrfid.common.enums.BusinessType;
import com.hxrfid.common.utils.poi.ExcelUtil;
import com.hxrfid.project.domain.bo.BsUserCommentBo;
import com.hxrfid.project.domain.vo.BsUserCommentVo;
import com.hxrfid.project.service.IBsUserCommentService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 用户评价
 *
 * @author hxrfid
 * @date 2025-06-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/project/userComment")
public class BsUserCommentController extends BaseController {

    private final IBsUserCommentService iBsUserCommentService;

    /**
     * 查询用户评价列表
     */
    @GetMapping("/list")
    public TableDataInfo<BsUserCommentVo> list(BsUserCommentBo bo, PageQuery pageQuery) {
        return iBsUserCommentService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用户评价列表
     */
    @Log(title = "用户评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BsUserCommentBo bo, HttpServletResponse response) {
        List<BsUserCommentVo> list = iBsUserCommentService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户评价", BsUserCommentVo.class, response);
    }

    /**
     * 获取用户评价详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<BsUserCommentVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iBsUserCommentService.queryById(id));
    }

    /**
     * 新增用户评价
     */
    @Log(title = "用户评价", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BsUserCommentBo bo) {
        return toAjax(iBsUserCommentService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改用户评价
     */
    @Log(title = "用户评价", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BsUserCommentBo bo) {
        return toAjax(iBsUserCommentService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除用户评价
     *
     * @param ids 主键串
     */
    @Log(title = "用户评价", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iBsUserCommentService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
